#pragma once

#include "stdafx.h"
#include "GlobalDefinition.h"
#include "Arena.h"

class CPool
{
public:
	static CPool* GetInstance();
	static void Destroy();
	
	void* Alloc(size_t size);
	void Free(void* p, size_t size);

private:
	// return the index of the arena that the p belongs to 
	int InWhichArena(size_t size)
	{
		if (size > SMALL_POOL_MAX)
		{
			return -1;
		}

		return ((size - 1) / 8);
	}

	CPool();
	~CPool();

private:
	CPool(CPool&);
	CPool operator=(CPool&);

private:
	CArena* m_pArenas[SMALL_POOL_MAX/MEMPOOL_ALIGNMENT];
	static CPool* m_sInstance;
};